/**
 * 检验报告管理初始化
 */
 var LabReport = {
    id: "LabReportTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1

};

/**
 * 初始化表格的列
 */
LabReport.initColumn = function () {
        return [
        {field: 'selectItem', radio: true},
        {title: '报告ID', width:'100', field: 'reportId', align: 'center', valign: 'middle', sortable: true},
        {title: '检验医嘱', width:'200', field: 'labset.orderLab.description', align: 'center', valign: 'middle', sortable: true},
        {title: '标本', width:'100', field: 'labVisit.specimen', align: 'center', valign: 'middle', sortable: true},
        {title: '状态', width:'100', field: 'busLabReportStatus.description', align: 'center', valign: 'middle', sortable: true},
        {title: '审核日期', width:'180', field: 'checkDate', align: 'center', valign: 'middle', sortable: true },
        {title: '审核人', width:'100', field: 'checkUserName', align: 'center', valign: 'middle', sortable: true},
        {title: '索引码', width:'100', field: 'xcode', align: 'center', valign: 'middle', sortable: true},
        {title: '业务数据类型', width:'100', field: 'data.description', align: 'center', valign: 'middle', sortable: true}
        ];
};

/**
 * 检查是否选中
 */
LabReport.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        LabReport.seItem = selected[0];
        return true;
    }
};

/**
 * 点击新增检验报告
 */
LabReport.add = function () {
    var index = Sys.open('新增检验报告',Sys.backendPath + '/cdc/labreport/to_add',['800px', '420px']);
    this.layerIndex = index;
};

/**
 * 打开查看检验报告详情
 */
LabReport.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('检验报告详情',Sys.backendPath + '/cdc/labreport/to_update/' + id,['800px', '420px']);
        this.layerIndex = index;
    }
};

/**
 * 删除检验报告
 */
LabReport.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/cdc/labreport/delete", function (data) {
	            Sys.success("删除成功!");
	            LabReport.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("labReportId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除检验报告?",operation);
    }
};

/**
 * 查询检验报告列表
 */
 LabReport.query = function () {
    if ((EpisodeIDTable.selEpisode)&&(EpisodeIDTable.selEpisode.id)) {
        var queryData=queryData = '{"NotQuery":"false","episodeId":"' + EpisodeIDTable.selEpisode.id + '"}';
        queryData = JSON.parse(queryData);
        LabReport.table.clear();
        LabReport.table.refresh({ query: queryData });
    }else{
        Sys.info('请先选择患者！' );
    }
};


 LabReport.ClickRow=function (r,e,f){
     LabResult.labreportId=r.id;
     LabResult.table.clear();
     LabResult.table.refresh({query: {labReportId:r.id}});

 };


$(function () {
    var defaultColunms = LabReport.initColumn();
    var table = new BSTable(LabReport.id, Sys.backendPath + "/cdc/labreport/list", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(20);
    table.setShowRefresh(false);
    table.setShowColumns(false);
    table.setShowToggle(false);
    table.setShowExport(false);
    table.setSubHead(80);
    table.setQueryParams({ NotQuery: true });

    table.setOnClickRow(LabReport.ClickRow);

    LabReport.table = table.init();
    LabReport.query();
});

